/*
 * Created on 9-nov-07
 *
 */
package be.donovan.gui.helper.components;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import org.joda.time.base.AbstractInstant;
import org.joda.time.base.AbstractPartial;

import be.donovan.gui.helper.DateTimeHelper;


public class DateTimeRenderer implements TableCellRenderer {
	private JLabel label = null;

	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column) {
		label = new JLabel();
		label.setOpaque(true);
		if (value != null) {
			if (value instanceof AbstractInstant)
				label.setText(DateTimeHelper.toZouluoDTG((AbstractInstant) value));
			else if (value instanceof AbstractPartial)
				label.setText(DateTimeHelper.toYearMonthDay((AbstractPartial) value));
		}
		if (isSelected)
			label.setBackground(JXTableDecorator.selectionBackgroundColor);
		return label;

	}
}
